from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select

# 打开浏览器
driver = webdriver.Firefox()
# 双击打开百度页面
driver.get('https://www.jiuxian.com/')
sleep(2)
# 窗口最大化
driver.maximize_window()
sleep(2)
# 点击请登录
driver.find_element(By.CLASS_NAME, 'headerLogin').click()
sleep(2)
# 输入手机号
driver.find_element(By.ID, 'userName').send_keys('15985645480')
sleep(2)
# 输入密码
driver.find_element(By.ID, 'password').send_keys('gW09092434')
# 强制等待 用户点击图片输入验证码
sleep(20)
# 点击登录按钮
driver.find_element(By.NAME, 'bi_Usuallogin').click()
sleep(2)
# 点击确认
driver.find_element(By.ID, 'bindSub').click()
sleep(5)
# 点击我的酒仙
driver.find_element(By.XPATH, '/html/body/div[2]/div/div[2]/ul/li[1]/div[1]/a').click()
sleep(2)
# 窗口切换
driver.switch_to.window(driver.window_handles[-1])
sleep(2)
# 点击完善资料
driver.find_element(By.CLASS_NAME, 'uGuideBut').click()
sleep(2)
# 向下滚动800像素
driver.execute_script('window.scrollTo(0, 800)')
sleep(2)
# 点击收货地址
driver.find_element(By.XPATH, '//a[@href="/myaccount/address.htm"]').click()
sleep(2)
# 输入收件人
driver.find_element(By.ID, 'people').send_keys('小高先生')
sleep(2)

# 选择地址
province = Select(driver.find_element(By.ID, 'province'))
province.select_by_value('2')
sleep(2)
city = Select(driver.find_element(By.ID, 'city'))
city.select_by_index(1)
sleep(2)
district = Select(driver.find_element(By.NAME, 'district'))
district.select_by_visible_text('昌平区')
sleep(2)

# 输入详细地址
driver.find_element(By.NAME, 'addressMore').send_keys('南口南大街21号')
sleep(2)
# 输入邮箱编号
driver.find_element(By.ID, 'zipcode').send_keys('101010')
sleep(2)
# 输入手机号
driver.find_element(By.ID, 'iphone').send_keys('15985645480')
sleep(2)
# 点击确定
driver.find_element(By.CLASS_NAME, 'qjwSubmit2').click()
sleep(2)
# 点击删除
driver.find_element(By.XPATH, '/html/body/div[4]/div[3]/div[2]/div[1]/table/tbody/tr[2]/td[4]/a[2]').click()
sleep(2)
# 点击确定  删除
driver.find_element(By.XPATH, '/html/body/div[8]/div/div[3]/span[1]').click()
sleep(2)
# 删除成功 点击确定
driver.find_element(By.XPATH, '/html/body/div[8]/div/div[3]/span[1]').click()
sleep(10)






